package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.mapper.CategoryMapper;
import cn.tedu.csmall.product.pojo.dto.BrandAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.CategoryAddNewDTO;
import cn.tedu.csmall.product.service.BrandService;
import cn.tedu.csmall.product.service.CategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "03.类别管理模块")
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    public CategoryController() {
        System.out.println("创建控制器类对象：AlbumController");
    }

    // http://localhost:8080/category/add-new?name=TestBrandName001&description=TestDescription001&sort=77
    @ApiOperation("添加类别")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody CategoryAddNewDTO categoryAddNewDTO) {
        log.debug("开始处理【添加品牌】的请求，参数：{}", categoryAddNewDTO);
        categoryService.addNew(categoryAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:8080/category/delete?id=1
    @ApiOperation("删除类别")
    @ApiOperationSupport(order = 200)
    @PostMapping("/delete")
    public String delete(Long id) {
        log.debug("开始处理【删除品牌】的请求，参数：{}", id);
        categoryService.delete(id);
        return "OK";
    }
}
